qemu-dm: Nicely terminate the device model script, to let it properly
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 18 Jan 2008 13:35:05 +0000 (13:35 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 18 Jan 2008 13:35:05 +0000 (13:35 +0000)
clean resources.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
tools/ioemu/target-i386-dm/helper2.c
tools/python/xen/xend/image.py

index e0f16845f659df24dfd75bdd2a0faa45036527be..03dd7e85072ab8c1da3ebd575cdb77c943ce6a42 100644 (file)
@@ -637,6 +637,7 @@ int main_loop(void)
     int evtchn_fd = xce_handle == -1 ? -1 : xc_evtchn_fd(xce_handle);
     char qemu_file[PATH_MAX];
     fd_set fds;
+    int ret = 0;
 
     buffered_io_timer = qemu_new_timer(rt_clock, handle_buffered_io,
                                       cpu_single_env);
@@ -647,10 +648,15 @@ int main_loop(void)
 
     xenstore_record_dm_state("running");
     while (1) {
-        while (!(vm_running && suspend_requested))
+        while (!((vm_running && suspend_requested) || shutdown_requested))
             /* Wait up to 10 msec. */
             main_loop_wait(10);
 
+        if (shutdown_requested) {
+            ret = EXCP_INTERRUPT;
+            break;
+        }
+
         fprintf(logfile, "device model saving state\n");
 
         /* Pull all outstanding ioreqs through the system */
@@ -676,7 +682,7 @@ int main_loop(void)
         xenstore_record_dm_state("running");
     }
 
-    return 0;
+    return ret;
 }
 
 void destroy_hvm_domain(void)
index 85e7e4fa08edc7211c6dc5dd53cc0b5cf8d06c12..ca79cb8faedfb92671fe5fa8d10130f4900a4e33 100644 (file)
@@ -321,7 +321,7 @@ class ImageHandler:
             return
         if self.pid:
             try:
-                os.kill(self.pid, signal.SIGKILL)
+                os.kill(self.pid, signal.SIGTERM)
             except OSError, exn:
                 log.exception(exn)
             try: